package com.qbccn.onlinetest.config.custom;

import com.qbccn.onlinetest.dto.ResponseResult;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author linke
 * @date 2020/7/12 23:37
 * @description
 */
@ControllerAdvice
public class CustomExceptionHandler {

  //捕获全局异常，处理所有不可知的异常
  @ExceptionHandler(value = Exception.class)
  @ResponseBody
  public ResponseResult handleException(Exception e, HttpServletRequest request) {
    return new ResponseResult(1, "出现异常", e.getMessage());
  }

  @ExceptionHandler(value = DataException.class)
  @ResponseBody
  public ResponseResult handleDataException(DataException e, HttpServletRequest request) {
    return new ResponseResult(1, "入参异常", e.getMessage());
  }

}
